from misc import ADC
import utime


class Light:
    def __init__(self):
        self.__adc = ADC()
        self.__adc.open()

    def __del__(self):
        self.__adc.close()

    def measure(self):
        l = 0
        vl = []
        for i in range(0, 9):
            v = self.__adc.read(ADC.ADC0)
            vl.append(v)
            utime.sleep_ms(20)
        vl.sort()
        v = vl[4]
        #r = 10 * v/(3300 - v)
        l = v
        vl.clear()
        return l
